package com.xmkj.bearbiz.home;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.common.Entity.SortEntity;
import com.common.widget.imageview.image.ImageLoaderUtils;
import com.sina.weibo.sdk.utils.ImageUtils;
import com.xmkj.bearbiz.R;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/8/1.
 */

public class SortTabAdapter extends RecyclerView.Adapter<SortTabAdapter.ViewHolder> {

    Context context;
    ArrayList<SortEntity.ListsEntity> list;



    public SortTabAdapter(Context context, ArrayList<SortEntity.ListsEntity> datas) {
        this.context = context;
        this.list = datas;

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        View view = View.inflate(context, R.layout.mine_tab, null);
        View view = LayoutInflater.from(context).inflate(R.layout.mine_tab, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvName.setText(list.get(position).ctitle);
        ImageLoaderUtils.display(holder.ivImg,list.get(position).cicon);

        holder.main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickListener.click(position);
            }
        });


    }

    private ClickListener clickListener;

    public void setItemClick(ClickListener click) {
        this.clickListener = click;
    }

    public interface ClickListener {
        void click(int position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvName;
        ImageView ivImg;
        TextView tvStatus;
        View main;

        public ViewHolder(View itemView) {
            super(itemView);
            main = itemView;
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            ivImg = (ImageView) itemView.findViewById(R.id.iv_pic);
        }
    }
}


